#!/usr/bin/env python

# encoding: utf-8

'''
 * Create File my_selenium_spider
 * Created by leixu on 2017/10/23
 * IDE PyCharm
'''
# from luobo.spider import patch_gevent
#
# # 如果执行的是远程方式需要 执行如下语句
# # 如果是本地执行的则需要   注释如下语句
# patch_gevent()
from luobo.spider.base_spider import ScriptRunMode
from luobo.spider.spiders import SeleniumBaseSpider, AsyncCrawlerRuler
from datetime import datetime


class LinkedinSpider(SeleniumBaseSpider):
    def __init__(self):
        super(LinkedinSpider, self).__init__()
        self.RUN_MODE = ScriptRunMode.LOCAL
        self.setting.PARALLEL_WORKER_NUMBERS = 1

    def start_crawler(self):
        ruler = AsyncCrawlerRuler()
        ruler.load_script("./script/linkedin_script.py")
        ruler.rule_index = 2
        self.crawler_feeder.add(ruler, self.do_process)

    def do_process(self, response):
        print("end")
        print(datetime.now())
        print(response)

    def add_params(self):
        args = []
        self.params_deliver.add_params(*args)

    def print_state(self):
        print(self.spider_state)


def process_1():
    b = LinkedinSpider()
    b.start_crawl()


if __name__ == "__main__":
    process_1()
